﻿Namespace [structure]
    Public Class CommaList
        'created by : sum
        'created date: 22/11/11
        'this structure is use to construct 1,2,3,4,5 pattern string
        'modified by: sum
        'modified date: 4/1/2011

        Private _data As String
        Private flag As eflag = eflag.begin
        Private _count As Integer = 0
        Private Enum eflag
            begin
            middle
        End Enum
        Public Sub New()
            _data = ""
            _count = 0
            flag = eflag.begin
        End Sub

        ''' <summary>
        ''' inject function is allow you to insert data to this structure by comma string 
        ''' </summary>
        ''' <param name="str"></param>
        ''' <remarks></remarks>
        Public Sub inject(ByVal str As String)
            For Each i In str.Split(","c)
                _count += 1
                Add(i)
            Next

        End Sub

        Public Function Count() As Integer
            Return _count
        End Function

        Public Sub Add(ByVal data As String)
            If flag = eflag.middle Then
                _data &= ","
            ElseIf flag = eflag.begin Then
                flag = eflag.middle
            End If
            _data &= data
            _count += 1
        End Sub

        Public Function contains(ByVal Entry As String) As Boolean
            Dim found As Boolean = False
            If _data.Contains(Entry) Then
                found = True
            End If
            Return True
        End Function

        Public Overrides Function toString() As String
            Return _data
        End Function

        ''' <summary>
        ''' 
        ''' </summary>
        ''' <returns>exp: '2','23','21'</returns>
        ''' <remarks>exp: '2','23','21'</remarks>
        Public Function toStringWithQuote() As String
            Dim newStr As String = String.Empty
            Dim _stuc As New CommaList
            For Each i In _data.Split(","c)
                _stuc.Add("'" & i & "'")
            Next
            Return _stuc.toString
        End Function
    End Class

End Namespace
